package priv.tuyou.system.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import priv.tuyou.constants.WebContext;

public class LoginInterceptor extends HandlerInterceptorAdapter{

	private static final String[] IGNORE_URI = {"/login.action", "/logout.action"};
	
	@Override
	public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2) throws Exception {
		
		//过滤不用拦截的请求
		String url = arg0.getRequestURL().toString();
		for(String uri : IGNORE_URI){
			
			if(url.contains(uri)){
				
				return true;
			}
		}
		if(WebContext.getSystemUser() == null){
			
			arg0.getRequestDispatcher("/WEB-INF/jsp/manager/common/login.jsp").forward(arg0, arg1);
			return false;
		}
		return true;
	}
}
